<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="awesome.Manager.ItemManager" %>
<%@ page import="awesome.Manager.PictureManager" %>
<%@ page import="awesome.Manager.BidManager" %>
<%@ page import="awesome.Manager.Item" %>
<%@include file='templates/header.jsp'%>
<%@ page import="java.util.LinkedList" %>
<%@ page import="java.util.ArrayList" %>
<%
	Boolean loggedIn = (Boolean)session.getAttribute("loggedIn");

	if(loggedIn == null){
		loggedIn = false;
	}
	
	String name = "";
	int uid = -1;

	if(loggedIn){
		name = (String)session.getAttribute("firstname");
		uid = (Integer)session.getAttribute("uid");	
	}
			
	ItemManager im = new ItemManager();
	PictureManager pm = new PictureManager();
	BidManager bm = new BidManager();
%>	
<h1> Welcome to Awesome Auctions <%=name%>. </h1>
	<table cellspacing="25">
		<tr>
			<td>
			<% 	
				if(loggedIn){
			%>		
					<h3>My Auctions:</h3>
					<table>				
			<% 			
					LinkedList<Item> items = im.getItemsForUser(uid);
				
					for(Item item : items){
						System.out.println(item.getItemID());
					%>
						<tr>
							<td>
								<img src="<%=pm.getThumbLoc(item.getItemID())%>" width="24" height="39"/>
							</td>
							<td>
							 	<a href="view_item.jsp?iid=<%=item.getItemID()%>"><%=item.getName()%></a>
							</td>
							<td>
								currentBid: $<%=bm.getCurrentBid(item.getItemID())%>
							</td>
						</tr>
					<% 
					}
				}
			%>
					</table>
		</td>
		<td>
			<h3>Top 5 Auctions:</h3>
			<table>				
			<% 			
				ArrayList<Item> items = im.getItems();
				
					for(int i = 0; i < 5 && i < items.size(); i++){
					%>
						<tr>
							<td>
								<img src="<%=pm.getThumbLoc(items.get(i).getItemID()) %>"/>
							</td>
							<td>
							 	<a href="view_item.jsp?iid=<%=items.get(i).getItemID()%>"><%=items.get(i).getName()%></a>
							</td>
							<td>
								currentBid: $<%=bm.getCurrentBid(items.get(i).getItemID())%>
							</td>
						</tr>
					<% 
					}
			%>
			</table>
		</td>
	</tr>
</table>
<%@include file='templates/footer.jsp'%>